package com.aimashi.railwaytoolmanagesystem.activity.scantool;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.aimashi.railwaytoolmanagesystem.R;
import com.aimashi.railwaytoolmanagesystem.bean.Card;

/**
 * 任务详情ListView使用
 * 
 * @author zhaoys
 *
 */
public class ToolAdapter extends BaseAdapter {
	private List<Card> list;
	private LayoutInflater inflater;
	private Context context;

	public ToolAdapter(Context context, List<Card> list) {
		this.context = context;
		this.list = list;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Card getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Card map = this.getItem(position);
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = inflater.inflate(R.layout.scantool_item, null);
			viewHolder.mTextEpcNumber = (TextView) convertView.findViewById(R.id.epcNumber);
			viewHolder.mTextEpcDesc = (TextView) convertView.findViewById(R.id.epcDesc);
			viewHolder.mTextEpcBack = (TextView) convertView.findViewById(R.id.epcBack);
			viewHolder.mTextScanTime = (TextView) convertView.findViewById(R.id.scanTime);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.mTextEpcNumber.setText(map.getEpcNumber());
		viewHolder.mTextEpcDesc.setText(map.getEpcDesc());
		String tempBack = "未检测";
		if(map.isBack()){
			tempBack = "吻合";
			viewHolder.mTextEpcNumber.setTextColor(context.getResources().getColor(R.color.red));
			viewHolder.mTextEpcDesc.setTextColor(context.getResources().getColor(R.color.red));
			viewHolder.mTextEpcBack.setTextColor(context.getResources().getColor(R.color.red));
			viewHolder.mTextScanTime.setTextColor(context.getResources().getColor(R.color.red));
		}else{
			viewHolder.mTextEpcNumber.setTextColor(context.getResources().getColor(R.color.black));
			viewHolder.mTextEpcDesc.setTextColor(context.getResources().getColor(R.color.black));
			viewHolder.mTextEpcBack.setTextColor(context.getResources().getColor(R.color.black));
			viewHolder.mTextScanTime.setTextColor(context.getResources().getColor(R.color.black));
		}
		viewHolder.mTextEpcBack.setText(tempBack);
		viewHolder.mTextScanTime.setText(map.getScanTime());
		return convertView;
	}
	public static class ViewHolder {
		public TextView mTextEpcNumber;
		public TextView mTextEpcDesc;
		public TextView mTextEpcBack;
		public TextView mTextScanTime;
	}

}
